@extends ('shop-backend::store.layout')

@section ('title',  '门店管理 | 添加门店')
@section('after-styles-end')
    {!! Html::style(env("APP_URL").'/assets/backend/libs/webuploader-0.1.5/webuploader.css') !!}
@stop
@section ('breadcrumbs')
    <h2>添加门店</h2>
    <ol class="breadcrumb">
        <li><i class="fa fa-dashboard"></i> 首页</li>
        <li>{!! link_to_route('admin.shop.list.store', '门店') !!}</li>
        <li class="active">添加门店</li>
    </ol>
@stop

@section('content')
    <div class="ibox float-e-margins">
        <div class="ibox-content" style="display: block;">
            {!! Form::open(['route' => 'admin.shop.list.store.save', 'class' => 'form-horizontal', 'id'=> 'create-store-form', 'role' => 'form', 'method' => 'post', 'files' => true]) !!}

            <div class="form-group">
                <label for="store-name" class="col-md-2 control-label">
                    <span style="color: red">*</span>门店名：
                </label>
                <div class="col-lg-10">
                    {!! Form::text('store-name', isset($store) && !empty($store->name) ? $store->name : null, ['class' => 'form-control', 'placeholder' => '', 'required']) !!}
                </div>
            </div>

            <div class="form-group">
                <label for="store-city" class="col-md-2 control-label">
                    <span style="color: red">*</span>所属城市：
                </label>
                <div class="col-lg-10">
                    {!! Form::select('store-city', $citys, isset($store) && !empty($store->city) ? $store->city : null, ['class' => 'form-control', 'placeholder' =>'', 'required']) !!}

                </div>
            </div>
            <div class="form-group">
                <label for="store-address" class="col-md-2 control-label">
                    <span style="color: red">*</span>地址信息：
                </label>
                <div class="col-lg-10">
                    {!! Form::text('store-address', isset($store) && !empty($store->address) ? $store->address : null, ['class' => 'form-control', 'placeholder' =>'某省某市某路某号', 'required']) !!}
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('store-phone', '联系电话', ['class' => 'col-lg-2 control-label']) !!}
                <div class="col-lg-10">
                    {!! Form::text('store-phone', isset($store) && !empty($store->phone) ? $store->phone : null, ['class' => 'form-control', 'placeholder' =>'']) !!}
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('store-img', '店铺图片', ['class' => 'col-lg-2 control-label']) !!}
                <div class="col-lg-10">
                    <input id="img_url" type="hidden" name="store-img" />
                    <input id="img_name" type="hidden" name="img_name" />
                    <div id="filePicker">选择图片</div>
                    <div class="clearfix"></div>
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('store-img', '已上传图片', ['class' => 'col-lg-2 control-label']) !!}
                <div class="col-lg-10">
                    @if(isset($store) && !empty($store->img_url))
                        <img src='{!! $store->img_url !!}'>
                    @endif
                </div>
            </div>

            <div class="form-group">
                <label class="col-lg-2 control-label">门店标签</label>
                <div class="col-lg-10">
                    @if (!empty($tags))
                        @foreach ($tags as $tag)
                            {!! Form::checkbox('store-tag[]', $tag->id , isset($store->tag) && $store->tag && substr_count($store->tag, $tag->id) ? true : null)  !!}
                            <img src="{{$tag->file_url}}">
                        @endforeach
                    @endif
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('store-act', '选择活动', ['class' => 'col-lg-2 control-label']) !!}
                <div class="col-lg-10">
                    {!! Form::select('store-act',$acts, isset($store) && !empty($store->act) ? $store->act : null, ['class' => 'form-control', 'placeholder' =>'']) !!}
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('store-code', '门店代码', ['class' => 'col-lg-2 control-label']) !!}
                <div class="col-lg-10">
                    {!! Form::text('store-code', isset($store) && !empty($store->code) ? $store->code : null, ['class' => 'form-control', 'placeholder' =>'']) !!}
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('store-type', '门店类型', ['class' => 'col-lg-2 control-label']) !!}
                <div class="col-lg-10">
                    {!! Form::text('store-type', isset($store) && !empty($store->type) ? $store->type : null, ['class' => 'form-control', 'placeholder' =>'']) !!}
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('store-is_enable', '是否启用', ['class' => 'col-lg-2 control-label']) !!}
                <div class="col-lg-10">
                    <input type="radio" name="store-is_enable" value="1" @if(isset($store) && !empty($store) && $store->is_enable ==1) checked @endif>是
                    <input type="radio" name="store-is_enable" value="0" @if(isset($store) && !empty($store) && $store->is_enable ==0) checked @endif>否
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('store-top', '是否置顶', ['class' => 'col-lg-2 control-label']) !!}
                <div class="col-lg-10">
                    <input type="radio" name="store-top" value="1" @if(isset($store) && !empty($store) && $store->top ==1) checked @endif>是
                    <input type="radio" name="store-top" value="0" @if(isset($store) && !empty($store) && $store->top ==0) checked @endif>否
                </div>
            </div><!--form control-->

            <div class="form-group">
                <div class="col-lg-10">
                    {!! Form::hidden('store-id', isset($store) && !empty($store->id) ? $store->id : null) !!}
                </div>
            </div>

            <div class="well">
                <div class="pull-right">
                    <input type="submit" class="btn btn-success btn-xs" value="保存" />
                </div>
                <div class="clearfix"></div>
            </div><!--well-->

            {!! Form::close() !!}
        </div>
    </div>
@stop
@section('before-scripts-end')
    {!! Html::script(env("APP_URL").'/assets/backend/libs/webuploader-0.1.5/webuploader.js') !!}
    <script>
        $(document).ready(function () {

            $('#create-store-form').ajaxForm({
                success: function (result) {
                    if (200 == result.code) {
                        swal({
                            title: "保存成功！",
                            text: "",
                            type: "success"
                        }, function () {
                            window.location = '{{route('admin.shop.list.store')}}';
                        });
                    } else {
                        swal("保存失败!", result.message, "error")
                    }

                }
            });

            // 初始化Web Uploader
            var uploader = WebUploader.create({
                auto: true,
                swf: '{{url(env("APP_URL").'/assets/backend/libs/webuploader-0.1.5/Uploader.swf')}}',
                server: '{{route('upload.image',['_token'=>csrf_token()])}}',
                pick: '#filePicker',
                fileVal: 'upload_image',
                accept: {
                    title: 'Images',
                    extensions: 'gif,jpg,jpeg,bmp,png',
                    mimeTypes: 'image/*'
                }
            });
            // 文件上传成功，给item添加成功class, 用样式标记上传成功。
            uploader.on('uploadSuccess', function (file, response) {
                console.log(file);
                $('#img_url').val(response.url);
                $('#img_name').val(file.name);
            });
        });
    </script>
@stop